//
//  WBNavigationController.swift
//  传智微博
//
//  Created by 郑亚伟 on 16/11/3.
//  Copyright © 2016年 郑亚伟. All rights reserved.
//

import UIKit

class WBNavigationController: UINavigationController {

        
    override func viewDidLoad() {
        super.viewDidLoad()
        //隐藏navigationBar，自定义一个
        navigationBar.isHidden = true
        //setupUI()
    }
    
     

    //重写push方法
    //所有的push直接调用该方法
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        //如果不是栈底控制器才需要隐藏，根控制器不需要隐藏
        //隐藏底部的tabbar
        if(childViewControllers.count > 0){
            viewController.hidesBottomBarWhenPushed = true
            
            /****************************************************/
            //判断控制器的类型
            if let vc = viewController as? WBBaseViewController{
                var title = "返回"
                //判断控制器级数 如果是二级页面，显示上一级标题，否则显示返回
                if childViewControllers.count == 1 {//push进入
                    //title显示首页标题  ???????????????????????????
                    title = childViewControllers.first?.title ?? "返回"
                }
                //取出自定义的navItem
                vc.navItem.leftBarButtonItem = UIBarButtonItem(title: title, fontSize: 16, target: self, action: #selector(popToParent),isBackButton: true)
            }
        }
        super.pushViewController(viewController, animated: true)
    }
    
    @objc private func popToParent(){
        popViewController(animated: true)
    }

    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        
    }
}
